{{ template "header.html" }}

<div class="item">
    WebToolsGo--简易Postman
</div>
<div class="item">
    <div>请求地址：</div>
    <label>
        <textarea name="url" placeholder="例如：https://www.baidu.com/"></textarea>
    </label>
</div>
<div class="item">
    <div>请求头（选填）：</div>
    <label>
        <textarea name="header" placeholder="例如：token=xxx&request_id=12"></textarea>
    </label>
</div>
<div class="item">
    <div>POST 请求参数（选填）：</div>
    <label>
        <textarea name="data" placeholder="例如：name=mmc&age=22"></textarea>
    </label>
</div>
<div class="item">
    <span>请求方式：</span>
    <label>
        <select name="type" id="">
            <option value="GET">GET</option>
            <option value="POST">POST</option>
            <option value="HEAD">HEAD</option>
            <option value="PUT">PUT</option>
            <option value="DELETE">DELETE</option>
        </select>
    </label>
</div>

<button onclick="sendRequest()">发送请求</button>

<div id="res"></div>

<script>
    function sendRequest() {
        var url = $("textarea[name='url']").val()
        var header = $("textarea[name='header']").val()
        var data = $("textarea[name='data']").val()
        var type = $("select[name='type']").val()
        $.post("/postman", {"url": url, "header": header, "data": data, "type": type }, function (res) {
            console.log(res)
            $("#res").text(res.resp)
        }, "json")
    }
</script>

{{ template "footer.html" }}